﻿using System;
using System.Text;
using System.Collections.Generic;
using OpenLibrary.Web.Controllers;
using System.Web.Mvc;
using OpenLibrary.Domain.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace OpenLibrary.Web.Tests.Controllers
{
    /// <summary>
    /// Summary description for PublishersControllerTests
    /// </summary>
    [TestClass]
    public class PublishersControllerTests
    {
        [TestMethod]
        public void GetCreateShouldReturnPublisherView()
        {
            var publishersController = new PublishersController();
            var result = publishersController.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Publisher));
        }

        [TestMethod]
        public void PostCreateShouldSavePublisherAndReturnDetailsView()
        {
            var publishersController = new PublishersController();
            var publisher = new Publisher()
            {
                Name = "Monjurul Habib",
                Email = "monjurul.habib@gmail.com",
                Phone = "8801751394958"
            };

            var result = publishersController.Create(publisher) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Details", result.ViewName);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Publisher));

            publisher = result.ViewData.Model as Publisher;
            Assert.IsNotNull(publisher);
            Assert.IsTrue(publisher.Id > 0);
        }
    }
}
